﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Zhaoxi.ReadingPlatform.BusinessInterface;
using Zhaoxi.ReadingPlatform.Models;
using Zhaoxi.ReadingPlatform.WebSiteApi.Utility;

namespace Zhaoxi.ReadingPlatform.WebSiteApi.Controllers
{
    public class BooksController : ControllerBase
    {
        private readonly ILogger<IndexController> _logger;
        // 分层架构中，不能再这样使用了。
        //private readonly DbContext _context;
        private readonly IBookService _bookService;

        public BooksController(ILogger<IndexController> logger, DbContext context, IBookService bookService)
        {
            _logger = logger;
            //_context = context;
            _bookService = bookService;
        }

        /// <summary>
        /// 获取图书的章节内容
        /// </summary>
        /// <param name="bookId"></param>
        /// <param name="chapterId"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("IndexBookChapterInfo/{bookId}/{chapterId}")]
        public IActionResult IndexBookChapterInfo(int bookId, int chapterId)
        {
            var bookChapterInfo = _bookService.IndexBookChapterInfo(out int finalChapter, bookId, chapterId);

            return new JsonResult(new ApiDataResult<BookChapterInfo>()
            {
                Success = true,
                Data = bookChapterInfo,
                OValue = finalChapter,
                Message = "图书章节"
            });
        }
    }
}
